package com.onesports.intelligent.k12.polarlight.controller.operation.order;

import cn.gjing.excel.executor.ExcelFactory;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.operation.CommissionDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.operation.CommissionPageVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.order.OrderByIdVO;
import com.onesports.intelligent.k12.polarlight.service.order.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author chenrl
 * @since 2022-7-8
 */
@Api(value = "运营", tags = "运营端-分佣记录")
@RestController
@RequestMapping(ApiPathConstants.COMMISSION)
@RequiredArgsConstructor
public class CommissionController {

    @Resource
    private final OrderService service;

    @ApiOperation("条件查询带分页")
    @GetMapping("/select-page")
    public ResponseEntity<IPage<CommissionPageVO>> selectPage(CommissionDTO commissionDTO) {
        return ResultUtil.success(service.selectPageByOperate(new Page<CommissionPageVO> (commissionDTO.getPage(),commissionDTO.getRow()), commissionDTO));
    }
    @ApiOperation("订单导出")
    @GetMapping("/export")
    public void export(HttpServletResponse response, CommissionDTO dto) {
        IPage<CommissionPageVO> commissionPageVOIPage = service.selectPageByOperate(new Page<>(1, Integer.MAX_VALUE), dto);
        ExcelFactory.createWriter(CommissionPageVO.class, response)
                .write(commissionPageVOIPage.getRecords()).flush();
    }
    @ApiOperation("根据id查询订单信息")
    @GetMapping("/select-by-id")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNo", value = "订单id", required = true, dataType = "String", paramType = "query"),
    })
    public ResponseEntity<OrderByIdVO> selectById(String orderNo) {
        return ResultUtil.success(service.selectById(orderNo));
    }
}